<?php


namespace App\Traits\Controllers;


use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

trait UpdateStatusTraits
{
    /**
     * @param $id
     * @param Request $request
     * @return \Dingo\Api\Http\Response
     * @throws ValidationException
     */
    public function status(Request $request)
    {

        //验证用户凭证信息
        $this->validateData($request);

        //得到传过来的id并分割为数组并过滤掉空值
        $ids = array_filter(explode(',',$request->input('ids')));

        if (empty($ids)) {
            return $this->response->errorBadRequest();
        }

        $this->getQuery()->whereIn('id',$ids)->update([
            'status' => $request->input('status')
        ]);

        return $this->response->noContent();
    }
}
